unit CommIPAddress;

{$ALIGN ON}
{$MINENUMSIZE 4}
{$WEAKPACKAGEUNIT}

interface

uses Windows, Messages;

const
  {$EXTERNALSYM ICC_INTERNET_CLASSES}
  ICC_INTERNET_CLASSES   = $00000800;

const
  {$EXTERNALSYM WC_IPADDRESS}
  WC_IPADDRESS         = 'SysIPAddress32';

  {$EXTERNALSYM IPN_FIRST}
  IPN_FIRST               = 0-860;       { internet address }
  {$EXTERNALSYM IPN_LAST}
  IPN_LAST                = 0-879;       { internet address }

  // Messages sent to IPAddress controls
  {$EXTERNALSYM IPM_CLEARADDRESS}
  IPM_CLEARADDRESS     = WM_USER+100;  { no parameters }
  {$EXTERNALSYM IPM_SETADDRESS}
  IPM_SETADDRESS       = WM_USER+101;  { lparam = TCP/IP address }
  {$EXTERNALSYM IPM_GETADDRESS}
  IPM_GETADDRESS       = WM_USER+102;  { lresult = # of non black fields.  lparam = LPDWORD for TCP/IP address }
  {$EXTERNALSYM IPM_SETRANGE}
  IPM_SETRANGE         = WM_USER+103;  { wparam = field, lparam = range }
  {$EXTERNALSYM IPM_SETFOCUS}
  IPM_SETFOCUS         = WM_USER+104;  { wparam = field }
  {$EXTERNALSYM IPM_ISBLANK}
  IPM_ISBLANK          = WM_USER+105;  { no parameters }

  {$EXTERNALSYM IPN_FIELDCHANGED}
  IPN_FIELDCHANGED     = IPN_FIRST - 0;

type
  {$EXTERNALSYM tagNMIPADDRESS}
  tagNMIPADDRESS = packed record
    hdr: NMHDR;
    iField: Integer;
    iValue: Integer;
  end;
  PNMIPAddress = ^TNMIPAddress;
  TNMIPAddress = tagNMIPADDRESS;

{ The following is a useful macro for passing the range values in the }
{ IPM_SETRANGE message. }
{$EXTERNALSYM MAKEIPRANGE}
function MAKEIPRANGE(low, high: Byte): LPARAM;

{ And this is a useful macro for making the IP Address to be passed }
{ as a LPARAM. }
{$EXTERNALSYM MAKEIPADDRESS}
function MAKEIPADDRESS(b1, b2, b3, b4: DWORD): LPARAM;

{ Get individual number }
{$EXTERNALSYM FIRST_IPADDRESS}
function FIRST_IPADDRESS(x: DWORD): DWORD;

{$EXTERNALSYM SECOND_IPADDRESS}
function SECOND_IPADDRESS(x: DWORD): DWORD;

{$EXTERNALSYM THIRD_IPADDRESS}
function THIRD_IPADDRESS(x: DWORD): DWORD;

{$EXTERNALSYM FOURTH_IPADDRESS}
function FOURTH_IPADDRESS(x: DWORD): DWORD;


implementation

{ IP Address edit control }

function MAKEIPRANGE(low, high: Byte): LPARAM;
begin
  Result := high;
  Result := (Result shl 8) + low;
end;

function MAKEIPADDRESS(b1, b2, b3, b4: DWORD): LPARAM;
begin
  Result := (b1 shl 24) + (b2 shl 16) + (b3 shl 8) + b4;
end;

function FIRST_IPADDRESS(x: DWORD): DWORD;
begin
  Result := (x shr 24) and $FF;
end;

function SECOND_IPADDRESS(x: DWORD): DWORD;
begin
  Result := (x shr 16) and $FF;
end;

function THIRD_IPADDRESS(x: DWORD): DWORD;
begin
  Result := (x shr 8) and $FF;
end;

function FOURTH_IPADDRESS(x: DWORD): DWORD;
begin
  Result := x and $FF;
end;

end.